// pages/test/test.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },

  onShow: function () {

  
  },
  onLoad: function (options) {
    if (!wx.getStorageSync('oid')) {
      wx.login({
        success: function (res) {
          var appid = 'wxd25d683eb8f015ca'
          var secret = '0eb21cff2bd745cc0ffde263ccab3ba1'
          if (res.code) {
          var ourl = "https://api.weixin.qq.com/sns/jscode2session?appid=" + appid + "&secret=" + secret + "&js_code=" + res.code + "&grant_type=authorization_code"
          app.C(res.code)
            wx.request({
              url: ourl,
              success: function (res) {
                console.log(res)
                wx.setStorageSync('oid', res.data.openid);
                console.log(112);
                console.log(wx.getStorageSync('oid'));
              }
            })
          } else {
            console.log(res.errMsg)
          }
        }
      })
    } else {
      console.log(11);
      console.log(wx.getStorageSync('oid'));
    }
  },

  formSubmit: function (e) {
    console.log(e.detail.value.key1);
    var key1 = e.detail.value.key1;
    var key2 = e.detail.value.key2;
    var key3 = e.detail.value.key3;
    var url = e.detail.value.url;
    var form_id = e.detail.formId;
    var oid = wx.getStorageSync('oid');
    var data = {
      key1: key1,
      key2: key2,
      key3: key3,
      form_id: form_id,
      oid: oid,
      url: url
    };
    // console.log(data);return;
    wx.request({
      url: 'http://translate.bmxx8.top/wx/xcx_send_template.php',
      data: data,
      success(res) {
        console.log(res)
      }
    })
  },


  /**
   * 生命周期函数--监听页面显示
   */


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return;
  }
})